import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Properties;

public class demo2 {
    public String read() throws IOException {
        //1.加载配置文件
        //1.1创建properties对象
        Properties myapp=new Properties();
        //1.2加载配置文件转换为一个集合
        //1.2.1获取class目录下的配置文件
        ClassLoader cl=demo.class.getClassLoader();//类加载器
        InputStream is= cl.getResourceAsStream("myapp.properties");
        myapp.load(is);

        //2.获取配置文件中定义的数据
        String className=myapp.getProperty("bootstrapClass");
        return className;
    }

    public Object createClass(String className) throws Exception {
        Class cls=Class.forName(className);
        //创建对象
        Object myclass=cls.newInstance();
        return myclass;
    }

    public Method method(String className) throws Exception {
        Method[] methods = Class.forName(className).getMethods();
        for(Method m:methods){
            if(m.isAnnotationPresent(InitMethod.class)){
                return m;
            }
        }
        return null;
    }

}
